//
//
//
//
//
//
// NetCDR.h
//

#ifndef _NET_CDR_H_
#define _NET_CDR_H_

#include "common.h"

class NetCDR
{
	public:
		static const U32 DEFAULT_LOCAL_BUFSIZE = 128;

	public:
		NetCDR();
		NetCDR(U32 size);
		NetCDR(const NetCDR& cdr);
		NetCDR(const char* data, U32 size);
		~NetCDR();

		NetCDR& operator= (const NetCDR& cdr);
		NetCDR& operator<< (U8 info);
		NetCDR& operator<< (S8 info);

		NetCDR& operator<< (U16 info);
		NetCDR& operator<< (S16 info);

		NetCDR& operator<< (U32 info);
		NetCDR& operator<< (S32 info);

		NetCDR& operator<< (const std::string& info);

		NetCDR& operator>> (U8& info);
		NetCDR& operator>> (S8& info);

		NetCDR& operator>> (U16& info);
		NetCDR& operator>> (S16& info);

		NetCDR& operator>> (U32& info);
		NetCDR& operator>> (S32& info);
		NetCDR& operator>> (std::string& info);

		NetCDR& operator>> (char* buf);

		bool EndBit(void);

		void Resize(U32 _newSize);
		void Clr(void);

		U32 FreeBytes();
		U32 Size();
		char* Data();
		char* RdPtr();
		char* WtPtr();

	private:
		void OrderChg(void* dst, void* src, U32 size);
		void ChkExceed(void* _newPtr);
		bool BigEndian();
		void NeedEnlg(U32 num);

	private:
		U32 _size;
		U32 _capacity;

		char* _rdPtr;
		char* _wtPtr;
		char* _ext;
		bool _bLocal;
		char _szLocal[DEFAULT_LOCAL_BUFSIZE];
};

#endif // _NET_CDR_H_
